package com.lp.biz.content.controller;

import com.lp.biz.content.model.query.CommentQuery;
import com.lp.biz.content.model.vo.CreateComment;
import com.lp.biz.content.service.CommentService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.CommentConstant.*;
import static com.lp.common.constant.MenuConstant.COMMENT_LIST;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-07-01 23:28:18
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 获取每日故事评论
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/daily")
    @PermissionAnnotation(menus = {COMMENT_LIST})
    public CommonResult getDailyCommentList(CommentQuery query) {
        query.setCommentType(CONTENT_TYPE_DAILY);
        return commentService.getCommentList(query);
    }

    /**
     * 获取共读会评论
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/reading")
    @PermissionAnnotation(menus = {COMMENT_LIST})
    public CommonResult getReadingCommentList(CommentQuery query) {
        query.setCommentType(CONTENT_TYPE_READING);
        return commentService.getCommentList(query);
    }

    /**
     * 获取听故事评论
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/story")
    @PermissionAnnotation(menus = {COMMENT_LIST})
    public CommonResult getStoryCommentList(CommentQuery query) {
        query.setCommentType(CONTENT_TYPE_STORY);
        return commentService.getCommentList(query);
    }

    /**
     * 删除评论
     * @param commentId 评论id
     * @return 处理结果
     */
    @DeleteMapping("/{commentId}")
    @PermissionAnnotation(menus = {COMMENT_LIST})
    public CommonResult deleteComment(@PathVariable Integer commentId) {
        commentService.deleteComment(commentId);
        return CommonResult.success();
    }

    /**
     * 回复
     * @param commentId 评论id
     * @return 处理结果
     */
    @PostMapping("/{commentId}/reply")
    @PermissionAnnotation(menus = {COMMENT_LIST})
    public CommonResult createReply(@PathVariable Integer commentId, @RequestBody@Validated CreateComment createComment) {
        commentService.createReply(commentId, createComment);
        return CommonResult.success();
    }
}
